home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / exidy.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  8KB  |  327 lines

  1. /***************************************************************************
  2.  
  3.   machine.c
  4.  
  5.   Functions to emulate general aspects of the machine (RAM, ROM, interrupts,
  6.   I/O ports)
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11.  
  12. /* These are defined in vidhrdw/exidy.c */
  13. extern unsigned char *exidy_sprite_enable;
  14. extern int exidy_collision;
  15. extern int exidy_collision_counter;
  16.  
  17. /* These are defined in sndhrdw/targ.c */
  18. extern unsigned char targ_spec_flag;
  19.  
  20.  
  21. /* also in drivers/exidy.c */
  22. #define PALETTE_LEN 8
  23. #define COLORTABLE_LEN 20
  24.  
  25. static unsigned char *palette;
  26. static unsigned short *colortable;
  27.  
  28. /* Arbitrary starting colors, modified by the game */
  29.  
  30. static unsigned char sidetrac_palette[3*PALETTE_LEN] =
  31. {
  32.     0x00,0x00,0x00,   /* BACKGND */
  33.     0x00,0x00,0x00,   /* CSPACE0 */
  34.     0x00,0xff,0x00,   /* CSPACE1 */
  35.     0xff,0xff,0xff,   /* CSPACE2 */
  36.     0xff,0xff,0xff,   /* CSPACE3 */
  37.     0xff,0x00,0xff,   /* 5LINES (unused?) */
  38.     0xff,0xff,0x00,   /* 5MO2VID  */
  39.     0xff,0xff,0xff    /* 5MO1VID  */
  40. };
  41.  
  42. static unsigned short sidetrac_colortable[COLORTABLE_LEN] =
  43. {
  44.     /* one-bit characters */
  45.     0, 4,  /* chars 0x00-0x3F */
  46.     0, 3,  /* chars 0x40-0x7F */
  47.     0, 2,  /* chars 0x80-0xBF */
  48.     0, 1,  /* chars 0xC0-0xFF */
  49.  
  50.     /* Motion Object 1 */
  51.     0, 7,
  52.  
  53.     /* Motion Object 2 */
  54.     0, 6,
  55.  
  56. };
  57.  
  58. static unsigned char venture_palette[3*PALETTE_LEN] =
  59. {
  60.     0x00,0x00,0x00,   /* BACKGND */
  61.     0x00,0x00,0xff,   /* CSPACE0 */
  62.     0x00,0xff,0x00,   /* CSPACE1 */
  63.     0x00,0xff,0xff,   /* CSPACE2 */
  64.     0xff,0x00,0x00,   /* CSPACE3 */
  65.     0xff,0x00,0xff,   /* 5LINES (unused?) */
  66.     0xff,0xff,0x00,   /* 5MO2VID */
  67.     0xff,0xff,0xff    /* 5MO1VID */
  68. };
  69.  
  70. /* Targ doesn't have a color PROM; colors are changed by the means of 8x3 */
  71. /* dip switches on the board. Here are the colors they map to. */
  72. static unsigned char targ_palette[3*PALETTE_LEN] =
  73. {
  74.                     /* color   use                            */
  75.     0x00,0x00,0xFF, /* blue    background             */
  76.     0x00,0xFF,0xFF, /* cyan    characters 192-255 */
  77.     0xFF,0xFF,0x00, /* yellow  characters 128-191 */
  78.     0xFF,0xFF,0xFF, /* white   characters  64-127 */
  79.     0xFF,0x00,0x00, /* red     characters   0- 63 */
  80.     0x00,0xFF,0xFF, /* cyan    not used               */
  81.     0xFF,0xFF,0xFF, /* white   bullet sprite          */
  82.     0x00,0xFF,0x00, /* green   wummel sprite          */
  83. };
  84.  
  85. /* Spectar has different colors */
  86. static unsigned char spectar_palette[3*PALETTE_LEN] =
  87. {
  88.                     /* color   use                            */
  89.     0x00,0x00,0xFF, /* blue    background             */
  90.     0x00,0xFF,0x00, /* green   characters 192-255 */
  91.     0x00,0xFF,0x00, /* green   characters 128-191 */
  92.     0xFF,0xFF,0xFF, /* white   characters  64-127 */
  93.     0xFF,0x00,0x00, /* red     characters   0- 63 */
  94.     0x00,0xFF,0x00, /* green   not used               */
  95.     0xFF,0xFF,0x00, /* yellow  bullet sprite          */
  96.     0x00,0xFF,0x00, /* green   wummel sprite          */
  97. };
  98.  
  99.  
  100. static unsigned short venture_colortable[COLORTABLE_LEN] =
  101. {
  102.     /* one-bit characters */
  103.     0, 4,  /* chars 0x00-0x3F */
  104.     0, 3,  /* chars 0x40-0x7F */
  105.     0, 2,  /* chars 0x80-0xBF */
  106.     0, 1,  /* chars 0xC0-0xFF */
  107.  
  108.     /* Motion Object 1 */
  109.     0, 7,
  110.  
  111.     /* Motion Object 2 */
  112.     0, 6,
  113.  
  114. };
  115.  
  116. static unsigned short pepper2_colortable[COLORTABLE_LEN] =
  117. {
  118.     /* two-bit characters */
  119.     /* (Because this is 2-bit color, the colorspace is only divided
  120.         in half instead of in quarters.  That's why 00-3F = 40-7F and
  121.         80-BF = C0-FF) */
  122.     0, 0, 4, 3,  /* chars 0x00-0x3F */
  123.     0, 0, 4, 3,  /* chars 0x40-0x7F */
  124.     0, 0, 2, 1,  /* chars 0x80-0xBF */
  125.     0, 0, 2, 1,  /* chars 0xC0-0xFF */
  126.  
  127.     /* Motion Object 1 */
  128.     0, 7,
  129.  
  130.     /* Motion Object 2 */
  131.     0, 6,
  132.  
  133. };
  134.  
  135. void exidy_vh_init_palette(unsigned char *game_palette, unsigned short *game_colortable,const unsigned char *color_prom)
  136. {
  137.     memcpy(game_palette,palette,3*PALETTE_LEN);
  138.     memcpy(game_colortable,colortable,COLORTABLE_LEN * sizeof(unsigned short));
  139. }
  140.  
  141.  
  142. unsigned char exidy_collision_mask = 0x00;
  143.  
  144. WRITE_HANDLER( fax_bank_select_w )
  145. {
  146.     unsigned char *RAM = memory_region(REGION_CPU1);
  147.  
  148.     cpu_setbank (1, &RAM[0x10000 + (0x2000 * (data & 0x1F))]);
  149.     cpu_setbankhandler_r (1, MRA_BANK1);
  150.     cpu_setbankhandler_w (1, MWA_ROM);
  151.  
  152.     if ((data & 0x1F)>0x17)
  153.     {
  154.         logerror("Banking to unpopulated ROM bank %02X!\n",data & 0x1F);
  155.     }
  156. }
  157.  
  158. READ_HANDLER( exidy_input_port_2_r )
  159. {
  160.     int value;
  161.  
  162.     /* Get 2 coin inputs and VBLANK */
  163.     value = readinputport(2);
  164.  
  165.     /* Combine with collision bits */
  166.     value = value | ((exidy_collision) & (exidy_collision_mask));
  167.  
  168.     /* Reset collision bits */
  169.     exidy_collision &= 0xEB;
  170.  
  171.     return value;
  172. }
  173.  
  174. void init_sidetrac(void) {
  175.     *exidy_sprite_enable = 0x10;
  176.     exidy_collision_mask = 0x00;
  177.     targ_spec_flag = 1;
  178.  
  179.     palette = sidetrac_palette;
  180.     colortable = sidetrac_colortable;
  181. }
  182.  
  183. void init_targ(void) {
  184.     *exidy_sprite_enable = 0x10;
  185.     exidy_collision_mask = 0x00;
  186.     targ_spec_flag = 1;
  187.  
  188.     palette = targ_palette;
  189.     colortable = venture_colortable;
  190. }
  191.  
  192. void init_spectar(void) {
  193.     /* Spectar does not have a sprite enable register so we have to fake it out */
  194.     *exidy_sprite_enable = 0x10;
  195.     exidy_collision_mask = 0x00;
  196.     targ_spec_flag = 0;
  197.  
  198.     palette = spectar_palette;
  199.     colortable = venture_colortable;
  200. }
  201.  
  202. void init_mtrap(void) {
  203.     /* Disable ROM Check for quicker startup */
  204.     #if 0
  205.     unsigned char *RAM = memory_region(REGION_CPU1);
  206.     RAM[0xF439]=0xEA;
  207.     RAM[0xF43A]=0xEA;
  208.     RAM[0xF43B]=0xEA;
  209.     #endif
  210.  
  211.     exidy_collision_mask = 0x14;
  212.  
  213.     palette = venture_palette;
  214.     colortable = venture_colortable;
  215. }
  216.  
  217. void init_pepper2(void) {
  218.     /* Disable ROM Check for quicker startup */
  219.     #if 0
  220.     unsigned char *RAM = memory_region(REGION_CPU1);
  221.     RAM[0xF52D]=0xEA;
  222.     RAM[0xF52E]=0xEA;
  223.     RAM[0xF52F]=0xEA;
  224.     #endif
  225.  
  226.     exidy_collision_mask = 0x14;
  227.  
  228.     palette = venture_palette;
  229.     colortable = pepper2_colortable;
  230. }
  231.  
  232. void init_venture(void) {
  233.     /* Disable ROM Check for quicker startup (Venture)*/
  234.     #if 0
  235.     unsigned char *RAM = memory_region(REGION_CPU1);
  236.     RAM[0x8AF4]=0xEA;
  237.     RAM[0x8AF5]=0xEA;
  238.     RAM[0x8AF6]=0xEA;
  239.     #endif
  240.     /* Disable ROM Check for quicker startup (Venture2)*/
  241.     #if 0
  242.     unsigned char *RAM = memory_region(REGION_CPU1);
  243.     RAM[0x8B04]=0xEA;
  244.     RAM[0x8B05]=0xEA;
  245.     RAM[0x8B06]=0xEA;
  246.     #endif
  247.  
  248.     exidy_collision_mask = 0x80;
  249.  
  250.     palette = venture_palette;
  251.     colortable = venture_colortable;
  252. }
  253.  
  254. void init_fax(void) {
  255.     /* Disable ROM Check for quicker startup */
  256.     #if 0
  257.     unsigned char *RAM = memory_region(REGION_CPU1);
  258.     RAM[0xFBFC]=0xEA;
  259.     RAM[0xFBFD]=0xEA;
  260.     RAM[0xFBFE]=0xEA;
  261.     /* Disable Question ROM Check for quicker startup */
  262.     RAM[0xFC00]=0xEA;
  263.     RAM[0xFC01]=0xEA;
  264.     RAM[0xFC02]=0xEA;
  265.     #endif
  266.  
  267.     exidy_collision_mask = 0x00;
  268.  
  269.     /* Initialize our ROM question bank */
  270.     fax_bank_select_w(0,0);
  271.  
  272.     palette = venture_palette;
  273.     colortable = pepper2_colortable;
  274. }
  275.  
  276. void exidy_init_machine(void)
  277. {
  278.     /* Nothing to do here now */
  279. }
  280.  
  281. int venture_interrupt(void)
  282. {
  283.     static int first_time = 1;
  284.     static int interrupt_counter = 0;
  285.  
  286.     exidy_collision = (exidy_collision | 0x80) & exidy_collision_mask;
  287.  
  288.     if (first_time)
  289.     {
  290.         first_time=0;
  291.         return nmi_interrupt();
  292.     }
  293.  
  294.     interrupt_counter = (interrupt_counter + 1) % 32;
  295.  
  296.     if (interrupt_counter == 0)
  297.     {
  298.         exidy_collision &= 0x7F;
  299.         return interrupt();
  300.     }
  301.  
  302.     if (exidy_collision_counter>0)
  303.     {
  304.         exidy_collision_counter--;
  305.         return interrupt();
  306.     }
  307.  
  308.     return 0;
  309. }
  310.  
  311. int exidy_interrupt(void)
  312. {
  313.     static int first_time = 1;
  314.  
  315.     exidy_collision = (exidy_collision | 0x80) & exidy_collision_mask;
  316.  
  317.     if (first_time)
  318.     {
  319.         first_time=0;
  320.         return nmi_interrupt();
  321.     }
  322.  
  323.     return interrupt();
  324. }
  325.  
  326.  
  327.